package pl.elka.simulator.core.configurationCommand.impl;

import java.util.List;

import pl.elka.simulator.core.Position;
import pl.elka.simulator.core.configurationCommand.ConfigurationCommandType;
import pl.elka.simulator.core.configurationCommand.ICommandParam;
import pl.elka.simulator.core.configurationCommand.IConfigurationCommand;
import pl.elka.simulator.core.configurationCommand.ables.IAbleToConfiguration;
import pl.elka.simulator.core.configurationCommand.ables.IAbleToLeaderConfiguration;
import pl.elka.simulator.core.mobilityManager.impl.nodes.LeaderNode;

public class AddLeaderConfigurationCommand implements IConfigurationCommand{

	private ICommandParam param;
	
	@Override
	public IConfigurationCommand newInstance() {
		return new AddLeaderConfigurationCommand();
	}

	@Override
	public void setParam(ICommandParam param) {
		this.param = param;
	}

	@Override
	public ICommandParam getParam() {
		return param;
	}

	@Override
	public ConfigurationCommandType getType() {
		return ConfigurationCommandType.AddLeaderConfigurationCommand;		
	}

	@Override
	public void execute(IAbleToConfiguration able) {
		IAbleToLeaderConfiguration al = (IAbleToLeaderConfiguration) able;
		
		Position position = CommandUtils.getPosition(this);
		List<LeaderNode> points = al.getLeaders();
		points.add(new LeaderNode(position));
		al.setLeaders(points);
	}

}
